﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PatternWell.PAC;

namespace $rootnamespace$
{
    //TODO:$safeitemname$ - Implement Model Contract 
    //Implement model contract on this instance of the partial class

    public partial class $safeitemname$
    {
        #region Logging Helper

        /// <summary>
        /// Partial helper method that will capture an exception and make it avaliable for logging.
        /// </summary>
        /// <param name="exception">The source exception that has occured.</param>
        /// <param name="methodQualifiedName">The fully qualified name of the method where the exception was caught.</param>
        partial void LogContractError(System.Exception exception, string methodQualifiedName);

        #endregion

        #region Dispose Implementation - Implementation of the disposal helper method (Do not modify)

        /// <summary>
        /// Helper method that releases resources for this class implementation.
        /// </summary>
        /// <param name="disposed">flag that determines if the class has already been disposed.</param>
        protected override void Dispose(bool disposed)
        {
            try
            {
                ReleaseResourcesFor$safeitemname$();
                base.Dispose(disposed);
            }
            catch(System.Exception disposeError)
            {
                LogContractError(disposeError, "$rootnamespace$.$safeitemname$.Dipose");
            }
        }

        #endregion

        #region Release Management - Logic used to release resources for this class (Add release logic in the supplied helper methods)

        /// <summary>
        /// Helper method that releases resource for the '$safeitemname$' class.
        /// </summary>
        private void ReleaseResourcesFor$safeitemname$()
        {
            try
            {
                //TODO:$safeitemname$ - ReleaseResourcesFor$safeitemname$
                //Dispose contract properties
                //Dispose contract events

                //Helper method will be executed if the partial method has been implemented. Otherwise it will be removed from the compile step.
                CleanupModel();
            }
            catch (System.Exception releaseError)
            {
                LogContractError(releaseError, "$rootnamespace$.$safeitemname$.ReleaseResourcesFor$safeitemname$");
            }
        }

        /// <summary>
        /// Helper method that runs additional release logic for the model that is not related to the model contract. 
        /// </summary>
        partial void CleanupModel();
        
        #endregion

        #region Model Initialization Logic

        public override void InitializeModel()
        {
            try
            {
                base.InitializeModel();

                //TODO:$safeitemname$ - Initialize Model
                //Initialize the model contract
                //Instance the properties and events of the contract.

                //Helper method will be executed if the partial method has been implemented. Otherwise it will be removed from the compile step.
                SetupModel();
            }
            catch (System.Exception initializeError)
            {
                LogContractError(initializeError, "$rootnamespace$.$safeitemname$.InitializeModel");
            }
        }

        /// <summary>
        /// Helper method that runs additional setup logic for the model that is not related to the model contract. 
        /// </summary>
        partial void SetupModel();

        #endregion

    }
}
